<?php
/**
 * Created by PhpStorm.
 * User: chenyulingxi
 * Date: 2020/7/11
 * Time: 2:26
 */

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

abstract class BaseRequest extends FormRequest
{
    public function getRouteRules()
    {
        $routeRules = $this->routeRules();
        $currentRouteName = $this->route()->getName();
        foreach ($routeRules as $routeNames => $rules) {
            foreach (explode('|', $routeNames) as $routeName) {
                if ($currentRouteName == $routeName) {
                    return $rules;
                }
            }
        }

        throw new \RuntimeException(sprintf('no rules for route: %s by %s::routeRules()', $currentRouteName, get_called_class()));
    }

    abstract public function routeRules(): array;

}